package com.grep.web.monitor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.grep.extra.dao.TaskDao;
import com.grep.extra.dao.impl.TaskDAOSQL;
import com.grep.extra.factory.data.impl.TaskUrl;
import com.grep.web.dto.SiteTaskDto;
import com.grep.web.dto.TaskNumber;

public class MonitorService {

	TaskDao taskDao = new TaskDAOSQL();
	
	public List<SiteTaskDto> getAllTasks(){
		List<SiteTaskDto> tasks = taskDao.getAllTasks();
		return tasks;
	}
	
	public List<TaskNumber> getTaskNumbersById(String taskId, int count){
		return taskDao.getTaskNumbersById(taskId, count);
	}
	
	/**
	 * 根据任务获取这些任务的指数
	 * @param tasks
	 * @return
	 */
	public Map<String, List<TaskNumber>> getTaskNumbersByTasks(List<TaskUrl> tasks){
		if(tasks == null || tasks.size() == 0){
			return null;
		}
		 Map<String, List<TaskNumber>> re = new HashMap<String, List<TaskNumber>>();
		for(TaskUrl task: tasks){
			List<TaskNumber> list = getTaskNumbersById(task.getId(), 10);
			re.put(task.getTaskName(), list);
		}
		return re;
	}
}
